home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / glass / glass.lha / GLASS / glue / tools.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-31  |  2.1 KB  |  98 lines

  1.  
  2. /*
  3.  
  4.     This file is a part of the GLASS source distribution 
  5.     and therefore subjected to the copy notice below. 
  6.     
  7.     Copyright (C) 1989,1990  S.J. Klaver, R Doesborg
  8.               email: simon@sagan.nl
  9.  
  10.     This program is free software; you can redistribute it and/or modify
  11.     it under the terms of the GNU General Public License as published by
  12.     the Free Software Foundation version 1
  13.  
  14.     This program is distributed in the hope that it will be useful,
  15.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.     GNU General Public License for more details.
  18.  
  19.     You should have received a copy of the GNU General Public License
  20.     along with this program; if not, write to the Free Software
  21.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  22. */
  23. #include <stdio.h>
  24. #include <tmc.h>
  25. #include "menuds.h"
  26.  
  27. extern string malloc();
  28.  
  29. int uppercase (k)
  30.   int k;
  31. {
  32.   if (k>='a' && k<='z')
  33.     return(k - 'a' + 'A');
  34.   else return(k);
  35. }
  36.  
  37. string converttouppercase (str)
  38.   string str;
  39. {
  40.   string hstr, loper;
  41.  
  42.   hstr = malloc(1+strlen(str));
  43.   strcpy(hstr, str);
  44.   for (loper = hstr; *loper != '\0'; loper++)
  45.     *loper = uppercase(*loper);
  46.   return(hstr);
  47. }
  48.  
  49. void convertlisttouppercase (strl)
  50.   string_list strl;
  51. {
  52.   int i;
  53.  
  54.   for (i=0; i<strl->sz; i++)
  55.     strl->arr[i] = converttouppercase(strl->arr[i]);
  56. }
  57.  
  58.  
  59. /* Given an integer 'mnr', find_menu finds the record in the 
  60.    data structure 'gl' with id 'mnr' and tag 'TAGMenu'.
  61. */
  62. Menu find_menu (gl, mnr)
  63.   gluefile gl;
  64.   int mnr;
  65. {
  66.   menparspec_list l;
  67.   int found;
  68.   int ix;
  69.  
  70.   l = ((Glue)gl)->specs;
  71.   found = 0;
  72.   ix=0;
  73.   while (ix<l->sz && !found)
  74.   {
  75.     if (l->arr[ix]->tag == TAGMenu)
  76.        found = (((Menu)l->arr[ix])->menuid) == mnr;
  77.     if (!found) ix++;
  78.   }
  79.   if (found)
  80.     return((Menu)l->arr[ix]);
  81.   else return((Menu)0);
  82. }
  83.  
  84. int find_item (cm, key)
  85.   Menu cm;
  86.   int key;
  87. {
  88.   int walker;
  89.   int found = 0;
  90.  
  91.   for (walker = 0; walker<cm->menuitems->sz && !found; walker++) {
  92.     found = (uppercase(cm->menuitems->arr[walker]->idchar) == uppercase(key));
  93.   }
  94.   if (!found)
  95.     return(-1);
  96.   else return(walker-1);
  97. }
  98.